package 力扣算法练习.main1.newPart1;

public class day4 {
    //https://www.nowcoder.com/questionTerminal/1277c681251b4372bdef344468e4f26e
    public int StrToInt(String str) {
        if(str.length()==0)return 0;
        char[] temp= str.toCharArray();
        boolean flag =false;
        int result=0;
        for(int i=0;i<temp.length;i++){
            char ch=temp[i];
            if(i==0){
                if(ch=='+'){
                    continue;
                }else if(ch=='-'){
                    flag=true;
                    continue;
                }
            }
            if(ch<48||ch>57){
                return 0;
            }
            if(ch!='0'){
                result+=(ch-'0');

            }
            if(i!=temp.length-1){
                result*=10;
            }
        }
        if(flag){
            result=-result;
        }
        return result;
    }

    public static void main(String[] args) {
        day4 iu=new day4();
        iu.StrToInt("-123");
    }
}
